package com.Controller;
import com.Utils.RedisUtil;
import com.Utils.Sample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("/testController")
public class AuthController {
    private Map<String, String> phoneVerificationCodes = new HashMap<>();
    @Autowired
    private RedisUtil redisUtil;
    @PostMapping("/send-verification-code")
    @ResponseBody
    public String sendVerificationCode(@RequestParam String phoneNumber) throws Exception {
        Object o = redisUtil.get("0");
        String code= Sample.message(phoneNumber);//调用工具类发送验证码
        phoneVerificationCodes.put(phoneNumber,code);
        return "success";
    }
    @PostMapping("/verify-code")
    public Map<String, Boolean> verifyCode(@RequestParam String phoneNumber, @RequestParam String code) {
        Map<String, Boolean> response = new HashMap<>();
        String savedCode = phoneVerificationCodes.get(phoneNumber);
        if (savedCode != null && savedCode.equals(code)) {
            response.put("success", true);
            // 验证成功后可以清除验证码或设置为已使用
            phoneVerificationCodes.remove(phoneNumber);
        } else {
            response.put("success", false);
        }
        return response;
    }
}
